package de.jadehs.cosima.internal;

import org.eclipse.core.runtime.IAdapterFactory;

import de.jadehs.cosima.Regex;
import de.jadehs.cosima.TransitionsTable;
import de.jadehs.cosima.converters.DFAToMinimalDFAConverter;
import de.jadehs.cosima.converters.EpsNFAToNFAConverter;
import de.jadehs.cosima.converters.NFAToDFAConverter;
import de.jadehs.cosima.converters.RegexToEpsNFAConverter;

@SuppressWarnings("rawtypes")
public class ProgramAdapterFactory implements IAdapterFactory {
	public Object getAdapter(Object adaptableObject, Class adapterType) {
		if (TransitionsTable.class != adapterType) {
			return null;
		}

		if (adaptableObject instanceof TransitionsTable) {
			return DFAToMinimalDFAConverter.INSTANCE
					.convert(NFAToDFAConverter.INSTANCE.convert(EpsNFAToNFAConverter.INSTANCE
							.convert((TransitionsTable) adaptableObject)));
			// return adaptableObject;
		} else if (adaptableObject instanceof Regex) {
			TransitionsTable epsNFA = RegexToEpsNFAConverter.INSTANCE
					.convert((Regex) adaptableObject);
			TransitionsTable nfa = EpsNFAToNFAConverter.INSTANCE
					.convert(epsNFA);
//			TransitionsTable dfa = NFAToDFAConverter.INSTANCE.convert(nfa);
//			TransitionsTable minDFA = DFAToMinimalDFAConverter.INSTANCE
//					.convert(dfa);
			return nfa;
		}

		return null;
	}

	public Class[] getAdapterList() {
		return new Class[] { TransitionsTable.class };
	}
}
